#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int* plusOne(int* digits, int digitsSize, int* returnSize)
{
    int newSize = sizeof(int) * (digitsSize + 1);
    int * result = (int *)malloc(newSize);
    memset(result,0x00,newSize);
    int flag = 1;
    for (int i = digitsSize - 1; i >= 0; i--){
        if (flag)
        {
            if (digits[i] + 1 == 10)
                result[i+1] = 0;
            else
            {
                result[i+1] = digits[i] + 1;
                flag = 0;
            }
        }
        else
            result[i+1] = digits[i];
    }
    if (flag)
    {
        result[0] = 1;
        *returnSize = digitsSize + 1;
    }
    else
    {
        *returnSize = digitsSize;
        memmove(&result[0],&result[1],sizeof(int) * digitsSize);
    }
    return result;
}


int main(void)
{

    int source[] = {1,2,3};
    int resultSize = 0;
    int * result = plusOne(source,3,&resultSize);
    printf("%d\n",resultSize);
    for (int i=0;i<resultSize;i++)
        printf("%d ,",result[i]);
    printf("\n");
    return 0;
}